package com.rentalHome.util;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonValue;

/**
 * Created by LeeXyan on 2017/03/01.
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
public class HttpResponse<R> {
    public enum Status {

        SUCCESS("success"), ERROR("error");

        private final String value;

        Status(String value) {
            this.value = value;
        }

        @JsonValue
        public String getValue() {
            return this.value;
        }
    }

    public HttpResponse() {
        this.result = null;
        this.successMsg = "SUCCESS";
        this.errorMsg = null;
    }

    public HttpResponse(R result) {
        this.result = result;
        this.successMsg = "SUCCESS";
        this.errorMsg = null;
    }

    public HttpResponse(R result, String successMsg) {
        this.result = result;
        this.successMsg = successMsg;
        this.errorMsg = null;
    }

    public HttpResponse(String errorMsg) {
        this.status = Status.ERROR;
        this.result = null;
        this.errorMsg = errorMsg;
        this.successMsg = null;
    }

    // Default value is success
    private Status status = Status.SUCCESS;

    // Result data
    private R result;

    // Success message
    private String successMsg;

    // Error message
    private String errorMsg;

    private String errorCode;

    public Status getStatus() {
        return status;
    }

    public void setStatus(Status status) {
        this.status = status;
    }

    public R getResult() {
        return result;
    }

    public void setResult(R result) {
        this.result = result;
    }

    public String getSuccessMsg() {
        return successMsg;
    }

    public void setSuccessMsg(String successMsg) {
        this.successMsg = successMsg;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.status = Status.ERROR;
        this.errorMsg = errorMsg;
    }

    public String getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }
}
